:- import "%%/lib/dynamic.sl" #

-= -- An indexer
? import "%%/lib/data.sl" #
? import "%%/lib/indexing.sl" #
?
stream.readFile IN "dictionary.txt",
forall (between 0 4000 .i) (stream.line IN .l, insert (WORD .l)),
stream.close IN,
index.buildUnique (WORD .) 1,
index.search (WORD "apple") #
=-

db.insert .record #
db.delete .record #
db.search .record #

db.load :-
	forall (table .t) (loadTable .t) #

loadTable .t :-
	concat .t ".table.sl" .filename,
	stream.readFile .stream .filename,
	forall (stream.line .stream .line) (
		parse .line .tuple,
		insert .tuple
	),
	stream.close .stream #
loadTable .t # -- Empty table

db.save :-
	forall (table .t) (saveTable .t) #

saveTable .t :-
	concat .t ".table.sl" .filename,
	stream.writeFile .stream .filename,
	forall (search .t) (
		stream.dump .stream .t,
		stream.nl .stream
	),
	stream.close .stream #
